package com.qingke.test7;

public class Car {
	public String name;
	public String type;
	public Battery bat;
	
	public Car() {
		
	}
	
//	有参构造
	public Car(String name,String type,Battery bat) {
		this.name=name;
		this.type=type;
		this.bat=bat;
	}
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}

	public Battery getBat() {
		return bat;
	}

	public void setBat(Battery bat) {
		this.bat = bat;
	}

	@Override
	public String toString() {
		return "name=" + name + ", type=" + type + ", bat=" + bat;
	}
	
	public void start() {
		int i = this.bat.usePower();
		if (i == 1) {
			System.out.println("电量充足,启动成功...");
		} else if (i == 0) {
			System.out.println("启动成功,电量过低，需要充电了...");
		}else {
			System.out.println("启动失败,需要充电...");
			this.bat.charge();
			start();
		}
	}
	

	class Battery {
		public int power = 1000;

		public int getPower() {
			return power;
		}

		public void setPower(int power) {
			this.power = power;
		}

		@Override
		public String toString() {
			return "[power=" + power + "]";
		}
		
		public int usePower() {
			if (power >= 300) {
				power = power - 100;
				return 1;
			}else if (power >= 100) {
				power = power - 100;
				return 0;
			}else {
				return -1;
			}
		}
		
		public void charge() {
			power = 1000;
		}
	}
}
